package com.github.sub.inter;

import com.github.Commander;
import com.github.Common;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.github.MyAutoTestContext.BLANK;
import static com.github.MyAutoTestContext.DBLANK;

public class HeaderCommander extends Common implements Commander {

    @Override
    public Object run(Map<String, String> command) {
        String value = command.get("-h");
        String[] keyValue = value.split(DBLANK);
        List<String> collect = Arrays.stream(keyValue).filter(s -> !s.equals(DBLANK)).collect(Collectors.toList());

        //只为别名创建header,根据别名查找域名，根据域名计算hashCode ，根据hashCode 创建header文件
        String domain = read(new File(alias + File.separator + keyValue[0]));
        StringBuilder stringBuilder = new StringBuilder();
        for (int i1 = 1; i1 < collect.size(); i1++) {
            stringBuilder.append(collect.get(i1)).append("\n");
        }
        tradition.outPutFile(stringBuilder.toString().getBytes(), header, domain.hashCode() + BLANK);
        return null;
    }
}
